<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Rollover | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'ilm-rollover.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/ilm-rollover.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/ilm-rollover.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/ilm-rollover.html" rel="nofollow" target="_blank">../en/ilm-rollover.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="index-lifecycle-management.html">ILM: Manage the index lifecycle</a></span>
»
<span class="breadcrumb-link"><a href="ilm-actions.html">Index lifecycle actions</a></span>
»
<span class="breadcrumb-node">Rollover</span>
</div>
<div class="navheader">
<span class="prev">
<a href="ilm-readonly.html">« Read only</a>
</span>
<span class="next">
<a href="ilm-set-priority.html">Set priority »</a>
</span>
</div>
<div class="section xpack">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="ilm-rollover"></a>Rollover<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ilm/actions/ilm-rollover.asciidoc">edit</a><a class="xpack_tag" href="https://www.elastic.co/subscriptions"></a>
</h2>
</div></div></div>
<p>Phases allowed: hot.</p>
<p>Rolls an alias over to a new index when the existing index meets one of the rollover conditions.</p>
<div class="important admon">
<div class="icon"></div>
<div class="admon_content">
<p>If the rollover action is used on a <a class="xref" href="ccr-put-follow.html" title="Create follower API">follower index</a>,
policy execution waits until the leader index rolls over (or is
<a class="xref" href="skipping-rollover.html" title="Skip rollover">otherwise marked complete</a>),
then converts the follower index into a regular index with the
<a class="xref" href="ilm-actions.html#ilm-unfollow-action">Unfollow action</a>.</p>
</div>
</div>
<p>For a managed index to be rolled over:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
The index name must match the pattern <em>^.*-\d+$</em>, for example (<code class="literal">my_index-000001</code>).
</li>
<li class="listitem">
The <code class="literal">index.lifecycle.rollover_alias</code> must be configured as the alias to roll over.
</li>
<li class="listitem">
The index must be the <a class="xref" href="indices-rollover-index.html#indices-rollover-is-write-index" title="Roll over a write index">write index</a> for the alias.
</li>
</ul>
</div>
<p>For example, if <code class="literal">my_index-000001</code> has the alias <code class="literal">my_data</code>,
the following settings must be configured.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT my_index-000001
{
  "settings": {
    "index.lifecycle.name": "my_policy",
    "index.lifecycle.rollover_alias": "my_data"
  },
  "aliases": {
    "my_data": {
      "is_write_index": true
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1112.console"></div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ilm-rollover-options"></a>Options<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ilm/actions/ilm-rollover.asciidoc">edit</a>
</h3>
</div></div></div>
<p>You must specify at least one rollover condition.
An empty rollover action is invalid.</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">max_age</code>
</span>
</dt>
<dd>
(Optional,  <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>)
Triggers roll over after the maximum elapsed time from index creation is reached.
</dd>
<dt>
<span class="term">
<code class="literal">max_docs</code>
</span>
</dt>
<dd>
(Optional, integer)
Triggers roll over after the specified maximum number of documents is reached.
Documents added since the last refresh are not included in the document count.
The document count does <span class="strong strong"><strong>not</strong></span> include documents in replica shards.
</dd>
<dt>
<span class="term">
<code class="literal">max_size</code>
</span>
</dt>
<dd>
<p>
(Optional, <a class="xref" href="common-options.html#byte-units" title="Byte size units">byte units</a>)
Triggers roll over when the index reaches a certain size.
This is the total size of all primary shards in the index.
Replicas are not counted toward the maximum index size.
</p>
<div class="tip admon">
<div class="icon"></div>
<div class="admon_content">
<p>To see the current index size, use the <a class="xref" href="cat-indices.html" title="cat indices API">_cat indices</a> API.
The <code class="literal">pri.store.size</code> value shows the combined size of all primary shards.</p>
</div>
</div>
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="ilm-rollover-ex"></a>Example<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ilm/actions/ilm-rollover.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="ilm-rollover-size-ex"></a>Roll over based on index size<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ilm/actions/ilm-rollover.asciidoc">edit</a>
</h4>
</div></div></div>
<p>This example rolls the index over when it is at least 100 gigabytes.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT _ilm/policy/my_policy
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover" : {
            "max_size": "100GB"
          }
        }
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1113.console"></div>
</div>

<div class="ilm-rollover-documents-ex]">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_roll_over_based_on_document_count"></a>Roll over based on document count<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ilm/actions/ilm-rollover.asciidoc">edit</a>
</h4>
</div></div></div>
<p>This example rolls the index over when it contains at least one hundred million documents.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT _ilm/policy/my_policy
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover" : {
            "max_docs": 100000000
          }
        }
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1114.console"></div>
</div>

<div class="ilm-rollover-age-ex]">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_roll_over_based_on_index_age"></a>Roll over based on index age<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ilm/actions/ilm-rollover.asciidoc">edit</a>
</h4>
</div></div></div>
<p>This example rolls the index over if it was created at least 7 days ago.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT _ilm/policy/my_policy
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover" : {
            "max_age": "7d"
          }
        }
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1115.console"></div>
</div>

<div class="ilm-rollover-conditions-ex]">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_roll_over_using_multiple_conditions"></a>Roll over using multiple conditions<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ilm/actions/ilm-rollover.asciidoc">edit</a>
</h4>
</div></div></div>
<p>When you specify multiple rollover conditions,
the index is rolled over when <em>any</em> of the conditions are met.
This example rolls the index over if it is at least 7 days old or at least 100 gigabytes.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT _ilm/policy/my_policy
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover" : {
            "max_age": "7d",
            "max_size": "100GB"
          }
        }
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1116.console"></div>
</div>

<div class="ilm-rollover-block-ex]">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_rollover_condition_blocks_phase_transition"></a>Rollover condition blocks phase transition<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ilm/actions/ilm-rollover.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The rollover action only completes if one of its conditions is met.
This means that any subsequent phases are blocked until rollover succeeds.</p>
<p>For example, the following policy deletes the index one day after it rolls over.
It does not delete the index one day after it was created.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /_ilm/policy/rollover_policy
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover": {
            "max_size": "50G"
          }
        }
      },
      "delete": {
        "min_age": "1d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1117.console"></div>
</div>

</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="ilm-readonly.html">« Read only</a>
</span>
<span class="next">
<a href="ilm-set-priority.html">Set priority »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>